<template>
    <div class="setting-container" @click="clickHandler">
        <SvgIcon name="setting"></SvgIcon>
    </div>
    <el-drawer
        title="设置"
        v-model="drawer"
        direction="rtl"
        :before-close="handleClose"
        destroy-on-close>
        <div class="setting-item">
            <span class="key">开启logo:</span>
            <el-switch @change="changeLogo" :value="iconSwitch"></el-switch>
        </div>

         <div class="setting-item">
            <span class="key">开启Tag:</span>
            <el-switch  @change="changeTag" :value="TagSwitch"></el-switch>
        </div>
            
    </el-drawer>
</template>

<script>
import { computed, ref } from 'vue'
import { useStore } from 'vuex'
export default {
    name: 'Setting',
    setup(){
        
        const store = useStore()
        let drawer = ref(false)

        let iconSwitch = computed(()=>{
            return store.state.setting.isLogo
        })

        let TagSwitch = computed(()=>{
            return store.state.setting.isTag
        })

        const clickHandler = ()=>{
            drawer.value = true
        }

        const changeLogo = ()=>{
            store.dispatch('setting/toggleLogo')
        }

        const changeTag = ()=>{
            store.dispatch('setting/toggleTag')
        }

        const handleClose = ()=>{
            drawer.value = false
        }
    
        return {clickHandler,drawer,handleClose,iconSwitch,TagSwitch,changeLogo,changeTag}
    }
}
</script>

<style lang="scss">
.setting-container{
    position: fixed;
    top: 40%;
    right: 0;
    background: #413b73;
    width: 52px;
    height: 52px;
    box-sizing: border-box;
    padding: 15px;
    border-radius: 3px;
    .icon{
        width: 24px !important;
        height: 24px !important;
        color: #fff;
    }

    &:hover{
        cursor: pointer;
    }
}

.setting-item{
    margin: 20px 0;
    .key{
        font-size: 14px;
        margin-right: 10px;
    }
}

.el-drawer__body{
    padding: 0 10px;
}
</style>